﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ImapX.Parsing.DataItems;

namespace ImapX.Parsing.Commands
{
    public class UidFetch : Command
    {
        int _uid;

        public UidFetch(int uid, params DataItem[] dataitems)
        {
            _uid = uid;
            parts = dataitems;
        }

        public override string Command
        {
            get
            {
                return "UID FETCH " + _uid.ToString() + " " + PartsCommand;
            }
        }

        protected override string BeginPattern
        {
            get
            {
                return @"\*" + SP + @"\d+" + SP + "FETCH" + SP + @"\(UID" + SP + _uid + SP;
            }
        }

        protected override string EndPattern
        {
            get
            {
                return @"\)";
            }
        }

        public override string Parse(string input)
        {
            if (IsMatch(input, @"IMAP\d+ OK")) throw new ImapException("Message not found.");

            return base.Parse(input);
        }
    }
}
